package cn.elead.chaos.core.list;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import cn.elead.chaos.core.enums.TypeEnum;

/**
 * @Auth 赵光
 * @Describle
 */
public final class Lists {

	/**
	 * 创建list
	 * 
	 * @param es
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <E> EasyList<E> newList(E... es) {
		return newList(Arrays.asList(es));
	}

	/**
	 * 创建list
	 * 
	 * @param list
	 * @return
	 */
	public static <E> EasyList<E> newList(Collection<E> list) {
		return EasyList.newList(list);
	}

	/**
	 * 创建set
	 * 
	 * @param es
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <E> Set<E> newHashSet(E... es) {
		return new HashSet<>(Arrays.asList(es));
	}

	/**
	 * 创建set
	 * 
	 * @param list
	 * @return
	 */
	public static <E> Set<E> newHashSet(Collection<E> list) {
		return new HashSet<>(list);
	}

	/**
	 * list to Array
	 * 
	 * @param c
	 * @param cls
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <E> E[] toArray(Collection<E> c, Class<E> cls) {
		return c.toArray((E[]) Array.newInstance(cls, c.size()));
	}

	/**
	 * list to Array
	 * 
	 * @param c
	 * @param cls
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <E> E[] toArray(Collection<E> c, TypeEnum typeEnum) {
		return c.toArray((E[]) Array.newInstance(typeEnum.getJavaType(), c.size()));
	}

}
